<template>
    <div class="cart" @click="$emit('hide')">
        <!-- 阻止事件冒泡 -->
        <div class="content" @click="$event.stopPropagation()">
            <!-- 列表 -->
            <div class="list" v-if="cartList.length > 0">
                <div class="item" v-for="(item,index) in cartList" :key="index">
                    <div class="pic">
                        <img :src="item.pic" alt="">
                    </div>
                    <div class="text">
                        <div class="name">{{item.name}}</div>
                        <div>{{item.desc}}</div>
                        <div>¥{{item.price}}</div>
                    </div>
                    <div class="btns">
                        <div class="btn sub" @click="add_to_cart(item)">-</div>
                        <div class="num" >{{item.count}}</div>
                        <div class="btn add" @click="add_count(item.id)">+</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import {mapState,mapMutations} from 'vuex'

export default {
    data(){
        return {

        }
    },
    computed:{
        ...mapState(['cartList'])
    },
    methods:{
        ...mapMutations(['add_count'])
    }
}
</script>
<style scoped >
.cart{
    background-color: rgba(0, 0, 0, .5);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
}
.cart .content{
    position: absolute;
    bottom: 0;
    width: 100%;
    min-height: 200px;
    background-color: white;
}


.cart .list .item{
    position: relative;
    display: flex;
    margin: 20px;
}
.cart .list .item .btns{
    position: absolute;
    right: 0;
    bottom: 0;
    display: flex;
    width: 100px;
    justify-content: space-between;
    line-height: 20px;
    text-align: center;
}
.cart .list .item .btns .btn{
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: lightskyblue;
    color: white;
}
.cart .list .item .pic{
    width: 80px;
    margin-right: 20px;
}
.cart .list .item .pic img{
    width: 100%;
}

.cart .list .item .text{
    flex: 1;
}
.cart .list .item .text .name{
    font-weight: bold;
    margin-bottom: 10px;
}
</style>